package com.itboye.eweilisten.util.address;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.itboye.eweilisten.R;


public class AddressFragment extends BaseDialogFragment implements OnClickListener {


    private AddressSelectView addressSelect;

    public interface GetInforListener {
        public void onGetinforListener(String province, String city, String district, String provinceNo, String cityNo, String districtNo);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        View v = inflater.inflate(R.layout.fragment_address2, container, false);
        v.findViewById(R.id.btn_confirm).setOnClickListener(this);
        v.findViewById(R.id.btn_cler).setOnClickListener(this);
        addressSelect = (AddressSelectView) v.findViewById(R.id.addressselect);
        return v;
    }


    @SuppressLint("NewApi")
    @Override
    public void onClick(View arg0) {
        switch (arg0.getId()) {
            case R.id.btn_cler:
                this.dismiss();
                break;
            case R.id.btn_confirm:
                addressSelect.getAddressData();
                String provinceNo = Integer.toString(addressSelect.getProvinceNo());
                String cityNo = Integer.toString(addressSelect.getCityNo());
                String districtNo = Integer.toString(addressSelect.getDistrictNo());
                GetInforListener listener = (GetInforListener) getActivity();
                listener.onGetinforListener(addressSelect.getProvinceName(), addressSelect.getCityName(), addressSelect.getDistrictName(), provinceNo, cityNo, districtNo);
                this.dismiss();
                break;
        }

    }

}
